package view;

import Dao.UserDao;
import Dao.Users;

import java.sql.SQLException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        UserDao userDao = new UserDao();
        System.out.println("来的xx系统");
        while (true) {
            System.out.println("1.注册");
            System.out.println("2.登录");
            System.out.println("3.删除id");
            System.out.println("4.修改id");
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入你的选择：");
            int choice = scanner.nextInt();
            int i;
            int id;
            String name;
            String pwd;
            switch (choice) {
                case 1:
                    System.out.println("注册界面");
                    System.out.println("请输入用户名：");
                    String username = scanner.next();
                    System.out.println("请输入密码：");
                    String password = scanner.next();
                    i = userDao.addUser(username, password);
                    if (i > 0) {
                        System.out.println("注册成功");
                    } else {
                        System.out.println("注册失败");
                    }

                    break;
                case 2:
                    System.out.println("请输入用户名：");
                    name = scanner.next();
                    System.out.println("请输入密码：");
                    pwd = scanner.next();
                    Users users = userDao.login(name, pwd);
                    if (users != null) {
                        System.out.println("登录成功");
                    } else {
                        System.out.println("登录失败");
                    }
                    break;
                case 3:
                    System.out.println("请输入删除的id");
                    id = scanner.nextInt();
                    i = userDao.deleteUser(id);
                    if (i > 0) {
                        System.out.println("删除成功");
                    } else {
                        System.out.println("删除失败");
                    }
                    break;
                default:
                    System.out.println("输入错误");
                    break;

                case 4:
                    System.out.println("请输入要修改的id");
                    id = scanner.nextInt();
                    System.out.print("请输入用户名：");
                    name = scanner.next();
                    System.out.print("请输入密码：");
                    pwd = scanner.next();
                    i = userDao.updateUsers(id, name, pwd);
                    if (i > 0) {
                        System.out.println("修改成功");
                        System.out.println("修改后的用户名：" + name);
                        System.out.println("修改后的密码：" + pwd);
                        System.out.println("修改后的id：" + id);
                    } else {
                        System.out.println("修改失败");
                    }
                    break;

            }

        }
    }
}